package com.mallcai.bigdata.ladon.dpl.mapper.report;

import com.mallcai.bigdata.ladon.dpl.entity.report.Report;
import com.mallcai.bigdata.ladon.dpl.mapper.report.provider.ReportSqlProvider;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author gst
 * @date 2019-12-30 20:36
 */
@Repository
public interface ReportMapper {
    @InsertProvider(type = ReportSqlProvider.class, method = "insert")
    int insert(Report report);

    @UpdateProvider(type = ReportSqlProvider.class, method = "update")
    int update(Report report);

    @UpdateProvider(type = ReportSqlProvider.class, method = "delete")
    int delete(Report report);

    @SelectProvider(type = ReportSqlProvider.class, method = "findById")
    Report findById(@Param("id") Long id);

    @SelectProvider(type = ReportSqlProvider.class, method = "getByParams")
    List<Report> getByParams(@Param("params") Map<String, Object> params);

    @SelectProvider(type = ReportSqlProvider.class, method = "hasSameName")
    int hasSameName(@Param("groupIds") List<Long> groupIds, @Param("name") String name, @Param("filterId") Long filterId);

    @SelectProvider(type = ReportSqlProvider.class, method = "hasSameCode")
    int hasSameCode(@Param("groupIds") List<Long> groupIds, @Param("code") String code, @Param("filterId") Long filterId);

    @SelectProvider(type = ReportSqlProvider.class, method = "getSimpleReport")
    List<Report> getSimpleReport(@Param("simpleReport") Integer simpleReport);

    @SelectProvider(type = ReportSqlProvider.class, method = "getByIds")
    List<Report> getNameByIds(@Param("ids") List<Long> ids);

    @SelectProvider(type = ReportSqlProvider.class, method = "findByCode")
    Report findByCode(@Param("code") String code);

    @SelectProvider(type = ReportSqlProvider.class, method = "getOwnSimpleReport")
    List<Report> getOwnSimpleReport(@Param("createdBy") Long createdBy, @Param("roleIds") List<Long> roleIds);

    @SelectProvider(type = ReportSqlProvider.class, method = "getReportCodeAndName")
    List<Report> getReportCodeAndName();

    @Select({
            "SELECT COUNT(*) FROM " + ReportSqlProvider.TB_REPORT + " WHERE archive  = 0"
    })
    int getTotalReportSize();
}
